package cn.edu.hbpu.controller.v1;

import cn.edu.hbpu.common.R;
import cn.edu.hbpu.entity.FirstCategory;
import cn.edu.hbpu.service.FirstCategoryService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @author lcy
 * @date 2022/8/16 18:25
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/firstCategory")
public class FirstCategoryController {

    @Autowired
    private FirstCategoryService firstCategoryService;

    /**
     * 删除一级分类
     * @param fId
     * @return
     */
    @DeleteMapping("/{fId}")
    public R<String> deleteFirstCategory(@PathVariable("fId") String fId) {
        return firstCategoryService.deleteFirstCategory(fId);
    }

    /**
     * 分页查询一级分类。实现了搜索功能
     * @param searchField
     * @param searchText
     * @param startDateTime
     * @param endDateTime
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/pagingQuery")
    public R<Page<FirstCategory>> pagingQuery(String searchField, String searchText, String startDateTime, String endDateTime, @NotNull int page, @NotNull int pageSize) {
        return firstCategoryService.pagingQuery(searchField, searchText, startDateTime, endDateTime, page, pageSize);
    }
}
